package com.hsmpay.mobile.dao.user.impl;

import com.hsmpay.common.dao.Impl.BaseDaoSupport;
import com.hsmpay.mobile.dao.user.UserMoneyDao;
import com.hsmpay.mobile.pojo.user.UserMoney;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

/**
 * 用户虚拟货币 sqlmap 实现类  userMoneyDao
 * 对应的pojo 是 UserMoney
 *
 * @param <Entity>
 * @param <Query>
 * @author 颜铃璋
 *         建立时间：2013-1-21
 */
@Repository("userMoneyDao")
public class UserMoneyDaoImpl extends BaseDaoSupport<UserMoney, Long> implements UserMoneyDao<UserMoney, Long> {

    /**
     * 通过userId 修改用户虚拟货币
     *
     * @param userId
     * @param money
     * @return
     * @throws SQLException
     */
    public int updateUserMoneyByUserId(Long userId, Double money) throws SQLException {
        UserMoney userMoney = new UserMoney();
        userMoney.setUserId(userId);
        userMoney.setMoney(money);
        return updateUserMoneyByUserId(userMoney);
    }

    /**
     * 通过userId 修改用户虚拟货币
     *
     * @param userMoney
     * @return
     * @throws SQLException
     */
    public int updateUserMoneyByUserId(UserMoney userMoney) throws SQLException {
        return getSqlMapClientTemplate().update("userMoneySqlMap.updateUserMoneyByUserId", userMoney);
    }

    /**
     * 通过userId 修改用户 可用金额
     *
     * @param userId
     * @param money
     * @return
     * @throws SQLException
     */
    public int updateAvailMoneyByUserId(Long userId, Double availMoney) throws SQLException {
        UserMoney userMoney = new UserMoney();
        userMoney.setUserId(userId);
        userMoney.setAvailMoney(availMoney);
        return updateUserMoneyByUserId(userMoney);//getSqlMapClientTemplate().update("userMoneySqlMap.updateAvailMoneyByUserId", userMoney);
    }

    /**
     * 通过userId 查询用户虚拟货币
     *
     * @param userId
     * @return
     * @throws SQLException
     */
    public UserMoney searchUserMoneyByUserId(Long userId) throws SQLException {
        UserMoney userMoney = new UserMoney();
        userMoney.setUserId(userId);
        return searchEntity(userMoney);
    }
}
